package com.digital.welcome.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.digital.welcome.entity.PageRequest;
import com.digital.welcome.entity.SysLog;
import com.digital.welcome.mapper.SysLogMapper;
import com.digital.welcome.response.Result;
import com.digital.welcome.service.SysLogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements SysLogService {

    @Autowired
    private SysLogMapper sysLogMapper;

    @Override
    public String findPage(PageRequest pageRequest) {
        PageHelper.startPage(pageRequest.getPageNum(), pageRequest.getPageSize());
        List<SysLog> sysLogList = sysLogMapper.selectList(null);
        PageInfo<SysLog> pageInfo = new PageInfo<>(sysLogList);
        return JSON.toJSONString(new Result<>().setCode(1).setMessage("查询成功").setData(pageInfo));
    }

    @Override
    public String getUrl(SysLog sysLog) {
        QueryWrapper<SysLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dname", sysLog.getDname());
        return JSON.toJSONString(new Result<>().setCode(1).setMessage("查询成功").setData(sysLogMapper.selectOne(queryWrapper).getUrl()));
    }
}
